import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
import { getPopupContainer } from '@vben/utils';

import { Select } from 'ant-design-vue';

import { renderDict } from '#/utils/render';
import { calculateAge } from '#/utils/date/date-util';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'customerName',
    label: '客户名称',
  },
  {
    component: 'Input',
    fieldName: 'phone',
    label: '手机号码',
  },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '客户名称',
    field: 'customerName',
  },
  {
    title: '客户年龄',
    field: 'customerAge',
    slots: {
      default: ({ row }) => {
        if (row.customerBirth) {
          return `${calculateAge(row.customerBirth)}`;
        }
        return '-';
      },
    },
  },
  {
    title: '客户出生日期',
    field: 'customerBirth',
  },
  {
    title: '家庭身份',
    field: 'familyType',
    editRender: {},
    slots: {
      default: ({ row }) => {
        if (row.familyType) {
          return renderDict(row.familyType, DictEnum.SYS_FAMILY_TYPE);
        }
        return '-';
      },
      edit: ({ row }) => {
        const options = [
          { key: '户主', value: 'HZ' },
          { key: '夫妻', value: 'FQ' },
        ].map((item) => ({
          label: item.key,
          value: item.value,
        }));
        return (
          <Select
            class="w-full"
            getPopupContainer={getPopupContainer}
            options={options}
            placeholder={'请选择'}
            v-model:value={row.familyType}
            // onChange={(value) => {
            //   console.log(value);
            // }}
          />
        );
      },
    },
  },
  {
    title: '手机号',
    field: 'phone',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 180,
  },
];
